// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DepoQuery1.java

package MaintMenu.Shipinfo1;

import javax.swing.*;
import java.sql.*;

public class DepoQuery1
{


    public  DepoQuery1(String poid, String isCapa, String boName)
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement st = con.createStatement();
            Statement st2 = con.createStatement();
            Statement st3 = con.createStatement();
            Statement st4 = con.createStatement();
            Statement st5 = con.createStatement();
            String dataSourceName6 = "dbBL";
            String dbURL6 = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName6).toString();
            Connection con6 = DriverManager.getConnection(dbURL6, "", "");
            Statement st6 = con6.createStatement();
            Statement st7 = con6.createStatement();
            Statement st8 = con6.createStatement();
            if(isCapa.equals(""))
                isCapa = "C";
            try
            {
                st.execute((new StringBuilder()).append("select [ref#] as ref from tblpurchaseorders where poid = ").append(poid).append(";").toString());
                ResultSet rs = st.getResultSet();
                String container = null;
                if(rs != null)
                {
                    rs.next();
                    container = rs.getString("ref");
                }
                st2.execute((new StringBuilder()).append("select [part#] as part_no, duedate, invid, quantity, unitprice from tblpurchaseorderdetail where poid = ").append(poid).append(";").toString());
                ResultSet rs2 = st2.getResultSet();
                String duedate = null;
                String duedate1 = null;
                long invid = 0L;
                String part_no = null;
                double quantity = 0.0D;
                double unitprice = 0.0D;
                String description = null;
                String description1 = null;
                if(rs2 != null)
                {
                    rs2.next();
                    duedate = rs2.getString("duedate");
                    duedate1 = (new StringBuilder()).append(duedate.substring(5, 7)).append("/").append(duedate.substring(8, 10)).append("/").append(duedate.substring(2, 4)).toString();
                    st4.execute((new StringBuilder()).append("insert into tblcontainerheader(container,arrival) values ('").append(container).append("',#").append(duedate1).append("#);").toString());
                    st5.execute((new StringBuilder()).append("select * from tblcontainerheader where container = '").append(container).append("';").toString());
                    ResultSet rs5 = st5.getResultSet();
                    long containerKey = 0L;
                    if(rs5 != null)
                    {
                        rs5.next();
                        containerKey = rs5.getLong("containerkey");
                    }
                    st4.execute((new StringBuilder()).append("INSERT INTO TBLCONTAINERDETAIL ( CONTAINERKEY, INVID, PN, QTY, RECEIVED ) SELECT ").append(containerKey).append(", INVID, [PART#], quantity, 0 ").append("FROM tblpurchaseorderdetail ").append("where poid = ").append(poid).append(";").toString());
                    st4.execute((new StringBuilder()).append("UPDATE TBLCLN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.DEPO_P = B.PRICE where b.containername='").append(container).append("';").toString());
                    st4.execute((new StringBuilder()).append("UPDATE TBLLTN AS A INNER JOIN tblcontainershipped AS B ON A.[PART#]=B.dnk_no SET A.DEPO_P = B.PRICE where b.containername='").append(container).append("';").toString());
                    if(container.indexOf("bk") > 0 || container.indexOf("BK") > 0)
                    {
                        st6.execute("delete * from tbllt_work;");
                        st6.execute("delete * from tbllt_temp;");
                        st6.execute((new StringBuilder()).append("insert into tblcontainerheader(containerkey,container,arrival) values (").append(containerKey).append(", '").append(container).append("',#").append(duedate1).append("#);").toString());
                        st3.execute((new StringBuilder()).append("select [part#] as part_no, duedate, invid, quantity, unitprice, description from tblpurchaseorderdetail where poid = ").append(poid).append(";").toString());
                        for(ResultSet rs3 = st3.getResultSet(); rs3.next();)
                        {
                            invid = rs3.getLong("invid");
                            part_no = rs3.getString("part_no");
                            quantity = rs3.getDouble("quantity");
                            unitprice = rs3.getDouble("unitprice");
                            description = rs3.getString("description");
                            description1 = description.replace('\'', ' ');
                            try
                            {
                                st7.execute((new StringBuilder()).append("INSERT INTO TBLCONTAINERDETAIL ( CONTAINERKEY, INVID, PN, QTY, RECEIVED ) values(").append(containerKey).append(", ").append(invid).append(", '").append(part_no).append("', ").append(quantity).append(", 0);").toString());
                                st8.execute((new StringBuilder()).append("INSERT INTO TBLLT_WORK ( [PART#], SUPPLIER, DEPO, DEPO_P, DEPO_QP, [DEPO#], description ) values('").append(part_no).append("', 'D', ").append(quantity).append(", ").append(unitprice).append(", ").append(unitprice).append(", null, '").append(description1).append("');").toString());
                            }
                            catch(SQLException er) {
                                JOptionPane.showInputDialog(null,er);
                            }
                        }

                        st6.execute("INSERT INTO TBLLT_TEMP SELECT * FROM TBLLT_WORK;");
                    }
                }
            }
            catch(SQLException er)
            {
                er.printStackTrace();
                JOptionPane.showMessageDialog(null, er);
            }
            st.close();
            st2.close();
            st3.close();
            st4.close();
            st5.close();
            st6.close();
            st7.close();
            st8.close();
            con.close();
            con6.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e);
        }


    }
}
